package BaseDatos.DAO;

import BaseDatos.OcaMySQLDAO;
import com.mysql.jdbc.Connection;
import java.io.IOException;
import java.net.URL;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Angel Lopez
 */
public class MySQLDAOFactory extends DAOFactory {

    /**
     * method to create ORACLE connection
     **/
    public static Connection createConnection()  {
        
        Properties prop = new Properties();
        Connection con = null;
       
        try {
            try {
                Class.forName(Constants.DRIVER_MYSQL);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(MySQLDAOFactory.class.getName()).log(Level.SEVERE, null, ex);
            }
            URL url = ClassLoader.getSystemResource(Constants.PROPERTIES);
            prop.load(url.openStream());

        } catch (IOException e) {}
        
        // jdbc:oracle:thin:@ipServidor:puerto:nombreBD
        String cadConexion = prop.getProperty(Constants.CONEXION);
        String username = prop.getProperty(Constants.USER);
        String password = prop.getProperty(Constants.PASS);

        try {con = (Connection) DriverManager.getConnection(cadConexion, username, password);}
        catch (SQLException e){}
        finally{return con;}
    }


    @Override
    public OcaDAO getOcaDAO() {
        return new OcaMySQLDAO();
    }
    
}

